home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / UUCICO / DCPSTATS.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  7KB  |  217 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    File transfer information for UUPC/extended                     */
  3. /*                                                                    */
  4. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*
  8.  *       $Id: DCPSTATS.C 1.5 1993/04/11 00:34:11 ahd Exp $
  9.  *
  10.  *       $Log: DCPSTATS.C $
  11.  * Revision 1.5  1993/04/11  00:34:11  ahd
  12.  * Global edits for year, TEXT, etc.
  13.  *
  14.  * Revision 1.4  1993/03/06  23:04:54  ahd
  15.  * Lock host status file before updating
  16.  *
  17.  * Revision 1.3  1992/12/30  13:17:12  ahd
  18.  * Windows/NT changes
  19.  *
  20.  */
  21.  
  22. /*--------------------------------------------------------------------*/
  23. /*                       standard include files                       */
  24. /*--------------------------------------------------------------------*/
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <time.h>
  29. #include <stdlib.h>
  30.  
  31. /*--------------------------------------------------------------------*/
  32. /*                    UUPC/extended include files                     */
  33. /*--------------------------------------------------------------------*/
  34.  
  35. #include "lib.h"
  36. #include "dcp.h"
  37. #include "dcpstats.h"
  38. #include "stater.h"
  39. #include "hlib.h"
  40. #include "hostable.h"
  41. #include "hostatus.h"
  42. #include "security.h"
  43. #include "timestmp.h"
  44. #include "ssleep.h"
  45. #include "lock.h"
  46.  
  47. /*--------------------------------------------------------------------*/
  48. /*                          Global variables                          */
  49. /*--------------------------------------------------------------------*/
  50.  
  51. currentfile();
  52.  
  53. /*--------------------------------------------------------------------*/
  54. /*    d c s t a t s                                                   */
  55. /*                                                                    */
  56. /*    Report transmission information for a connection                */
  57. /*--------------------------------------------------------------------*/
  58.  
  59. void dcstats(void)
  60. {
  61.    if (hostp == BADHOST)
  62.    {
  63.       printmsg(0,"dcstats: host structure pointer is NULL");
  64.       panic();
  65.    }
  66.  
  67.    if (!equal(rmtname , hostp->hostname))
  68.       return;
  69.  
  70.    if (remote_stats.lconnect > 0)
  71.    {
  72.       time_t connected;
  73.       unsigned long bytes;
  74.       unsigned long bps;
  75.  
  76.       HostStatus();
  77.  
  78.       connected = time(NULL) - remote_stats.lconnect;
  79.       remote_stats.connect += connected;
  80.       bytes = remote_stats.bsent + remote_stats.breceived;
  81.  
  82.       if ( connected > 0 )
  83.          bps = bytes / (long unsigned) connected;
  84.       else
  85.          bps = 0;
  86.  
  87.       printmsg(0,"%ld files sent, %ld files received, "
  88.                  "%ld bytes sent, %ld bytes received",
  89.             remote_stats.fsent, remote_stats.freceived ,
  90.             remote_stats.bsent, remote_stats.breceived);
  91.       printmsg(0, "%ld packets transferred, %ld errors, "
  92.                   "connection time %ld:%02ld, %ld bytes/second",
  93.             (long) remote_stats.packets,
  94.             (long) remote_stats.errors,
  95.             (long) connected / 60L, (long) connected % 60L, bps);
  96.  
  97.    } /*if */
  98.    else
  99.       printmsg(0,"Unable to print information for host %s (%s)",
  100.             rmtname,
  101.             hostp->hostname);
  102.  
  103.    if (remote_stats.lconnect > hostp->hstats->lconnect)
  104.       hostp->hstats->lconnect = remote_stats.lconnect;
  105.  
  106.    if (remote_stats.ltime > hostp->hstats->ltime)
  107.       hostp->hstats->lconnect = remote_stats.lconnect;
  108.  
  109.    hostp->hstats->connect   += remote_stats.connect;
  110.    hostp->hstats->calls     += remote_stats.calls;
  111.    hostp->hstats->fsent     += remote_stats.fsent;
  112.    hostp->hstats->freceived += remote_stats.freceived;
  113.    hostp->hstats->bsent     += remote_stats.bsent;
  114.    hostp->hstats->breceived += remote_stats.breceived;
  115.    hostp->hstats->errors    += remote_stats.errors;
  116.    hostp->hstats->packets   += remote_stats.packets;
  117.  
  118. } /* dcstats */
  119.  
  120. /*--------------------------------------------------------------------*/
  121. /*    d c u p d a t e                                                 */
  122. /*                                                                    */
  123. /*    Update the status of all known hosts                            */
  124. /*--------------------------------------------------------------------*/
  125.  
  126. void dcupdate( void )
  127. {
  128.    boolean firsthost = TRUE;
  129.    struct HostTable *host;
  130.    FILE *stream;
  131.    char fname[FILENAME_MAX];
  132.    long size;
  133.    unsigned short len1 = strlen(compilep );
  134.    unsigned short len2 = strlen(compilev );
  135.    boolean gotlock;
  136.    short retries = 30;
  137.    LOCKSTACK savelock;
  138.  
  139.    mkfilename( fname, E_confdir, DCSTATUS );
  140.  
  141. /*--------------------------------------------------------------------*/
  142. /*            Save lock status, then lock host status file            */
  143. /*--------------------------------------------------------------------*/
  144.  
  145.    PushLock( &savelock );
  146.  
  147.    do {
  148.       gotlock = LockSystem( "*status", B_UUSTAT );
  149.       if ( ! gotlock )
  150.          ssleep(2);
  151.    } while ( ! gotlock && retries-- );
  152.  
  153.    if ( ! gotlock )
  154.    {
  155.       printmsg(0,"Cannot obtain lock for %s", fname );
  156.       PopLock( &savelock );
  157.       return;
  158.    }
  159.  
  160. /*--------------------------------------------------------------------*/
  161. /*                  Old previous status as required                   */
  162. /*--------------------------------------------------------------------*/
  163.  
  164.    HostStatus();              /* Get new data, if needed          */
  165.  
  166.    filebkup( fname );      /* Rename the file if desired       */
  167.  
  168.    if ((stream  = FOPEN(fname, "w", BINARY_MODE)) == NULL)
  169.    {
  170.       printerr( fname );
  171.       return;
  172.    }
  173.  
  174.    fwrite( &len1, sizeof len1, 1, stream );
  175.    fwrite( &len2, sizeof len2, 1, stream );
  176.    fwrite( compilep , 1, len1, stream);
  177.    fwrite( compilev , 1, len2, stream);
  178.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  179.  
  180.    while  ((host = nexthost( firsthost )) != BADHOST)
  181.    {
  182.       len1 = strlen( host->hostname );
  183.       len2 = sizeof *(host->hstats);
  184.  
  185.       firsthost = FALSE;
  186.  
  187.       fwrite( &len1, sizeof len1, 1, stream );
  188.       fwrite( &len2, sizeof len2, 1, stream );
  189.       fwrite( host->hostname , sizeof hostp->hostname[0], len1, stream);
  190.       host->hstats->save_hstatus = ( host->hstatus == called ) ?
  191.                                     succeeded : host->hstatus;
  192.       fwrite( host->hstats , len2, 1,  stream);
  193.    }
  194.  
  195. /*--------------------------------------------------------------------*/
  196. /*         Make we sure got end of file and not an I/O error          */
  197. /*--------------------------------------------------------------------*/
  198.  
  199.    if (ferror( stream ))
  200.    {
  201.       printerr( fname );
  202.       clearerr( stream );
  203.    }
  204.  
  205.    fclose( stream );
  206.  
  207.    hstatus_age = stater( fname , &size );
  208.  
  209. /*--------------------------------------------------------------------*/
  210. /*                      Restore locks and return                      */
  211. /*--------------------------------------------------------------------*/
  212.  
  213.    UnlockSystem( );
  214.    PopLock( &savelock );
  215.  
  216. } /* dcupdate */
  217.